package ThirdMax;

import java.util.Scanner;
import java.util.TreeSet;

/**
 * @author gao
 * @date 2025/11/12 16:12
 */

public class Solution {
    public int thirdMax(int[] nums) {
        TreeSet<Integer> set = new TreeSet<>();
        for (int i : nums) {
            set.add(i);
        }

        if (set.size() < 3) {
            return set.last();
        }

        set.remove(set.last());
        set.remove(set.last());

        return set.last();
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = in.nextInt();
            }
            Solution solution = new Solution();
            System.out.println(solution.thirdMax(nums));
        }
    }
}